package com.nju.bean.cloud;

import java.util.ArrayList;

public class Dot {
	private double ps_x,ps_y;
	public Object obj;
	public Dot(double x,double y,Object o){
		setPs_x(x);
		setPs_y(y);
		obj = o;
	}

	public double getDistance(Dot d){
		double x1 = (double)ps_x;
		double y1 = (double)ps_y;
		double x2 = (double)(d.getPs_x());
		double y2 = (double)(d.getPs_y());
		return Math.sqrt(Math.pow(x1-x2,2)+Math.pow(y1-y2, 2));
	}
	public void setPs_y(double ps_y) {
		this.ps_y = ps_y;
	}
	public double getPs_y() {
		return ps_y;
	}
	public void setPs_x(double ps_x) {
		this.ps_x = ps_x;
	}
	public double getPs_x() {
		return ps_x;
	}
	
	public ArrayList<Dot> getCloud(ArrayList<Dot> dl,double d){
		RelationMatrix rm = new RelationMatrix(dl,d);
		return rm.relatedDots(this);
	}
	
	public static Dot getCenter(ArrayList<Dot> dl){
		double ps_x= 0,ps_y = 0,sum = dl.size();
		for(Dot d:dl){
			ps_x += d.getPs_x();
			ps_y += d.getPs_y();
		}
		ps_x /= sum;
		ps_y /= sum;
		
		return new Dot(ps_x,ps_y,null);
	}
	
	public boolean inACloud(Dot dot,ArrayList<Dot> dl,double distance){
		return this.getCloud(dl, distance).contains(dot);
	}
}